#ifndef __SHT3x_H
#define __SHT3x_H

#include "main.h"
#include "sht30.h"

#define SHT30_HANDLE hi2c1
#define SHT30_ADDR 0x44
#define CRC8_POLYNOMIAL 0x31

#define	SHT30_ADDR_WRITE	0x44<<1         //10001000
#define	SHT30_ADDR_READ		(0x44<<1)+1	    //10001011

typedef enum
{
    /* ?????? */

    SOFT_RESET_CMD = 0x30A2,	
    /*
    ??????
    ????:Repeatability_CS_CMD
    CS: Clock stretching
    */
    HIGH_ENABLED_CMD    = 0x2C06,
    MEDIUM_ENABLED_CMD  = 0x2C0D,
    LOW_ENABLED_CMD     = 0x2C10,
    HIGH_DISABLED_CMD   = 0x2400,
    MEDIUM_DISABLED_CMD = 0x240B,
    LOW_DISABLED_CMD    = 0x2416,

    /*
    ??????
    ????:Repeatability_MPS_CMD
    MPS:measurement per second
    */
    HIGH_0_5_CMD   = 0x2032,
    MEDIUM_0_5_CMD = 0x2024,
    LOW_0_5_CMD    = 0x202F,
    HIGH_1_CMD     = 0x2130,
    MEDIUM_1_CMD   = 0x2126,
    LOW_1_CMD      = 0x212D,
    HIGH_2_CMD     = 0x2236,
    MEDIUM_2_CMD   = 0x2220,
    LOW_2_CMD      = 0x222B,
    HIGH_4_CMD     = 0x2334,
    MEDIUM_4_CMD   = 0x2322,
    LOW_4_CMD      = 0x2329,
    HIGH_10_CMD    = 0x2737,
    MEDIUM_10_CMD  = 0x2721,
    LOW_10_CMD     = 0x272A,
	/* ???????????? */
	READOUT_FOR_PERIODIC_MODE = 0xE000,
} SHT30_CMD;

struct THData {
	int err;
	float temp;
	float humi;
	int16_t Temp;
	int16_t Humi;
};

extern void SHT30_Reset(void);
extern void setSHT30Handle(void);
extern HAL_StatusTypeDef SHT30_Init(void);
extern HAL_StatusTypeDef SHT30_Dat_To_Float(uint8_t* const dat, float* temperature, float* humidity);
extern HAL_StatusTypeDef SHT30_Read_Dat(uint8_t* dat);
extern HAL_StatusTypeDef GET_STH30_DATA(struct THData *);
#endif
